<?php
session_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
  <head>
      <title>Netsuite - Bitzer</title>
      <!--<link rel="StyleSheet" href="assets/css/style.css" type="text/css" />-->

  </head>
  <body>

      <?php
            
            include("../includes/custom/bal_netsuite.php");

            if(isset ($_SESSION["searchKeyword"]))
            {
                $keyword = $_SESSION["searchKeyword"];
            }
            else
            {
                $keyword = "";
            }

            $bal = new BAL();

            $list_name = $bal->getList($_SERVER["QUERY_STRING"]);

            $results_list = $bal->getSearchResults($keyword, $list_name);

            //$all_current_result_items = $bal->getCountAtCurrentLevel();

      ?>

       <table data-bitzer-data="true"
              data-bitzer-title="Netsuite"
              data-bitzer-desc="Netsuite"
              data-bitzer-component="results"
              data-bitzer-record-count="<?php echo count($results_list); //$all_current_result_items; ?>"
              <?php
                if(!isset ($bal->params["recordCount"]) || $bal->params["recordCount"][0] == "N")
                {
              ?>
              data-bitzer-number-of-rows="<?php echo count($results_list); ?>"
              data-bitzer-start-index="<?php if(isset ($bal->params['startRow'])) { echo $bal->params['startRow'][0]; } else { echo "0"; } ?>"
              <?php
                }
              ?>
              width="100%">

           <?php
                if(isset ($bal->params["recordCount"]) && $bal->params["recordCount"][0] == "Y")
                {
           ?>
                    <tr>
                        <td>Record Count</td>
                        <td><?php echo $db->getRecordsCount("sites"); ?></td>
                    </tr>

           <?php
                }
                else
                {
           ?>
                    <th data-bitzer-field="list_name">List</th>
                    <th data-bitzer-field="item_id"  data-bitzer-key-order="1">Item</th>
                    <th data-bitzer-field="description">Description</th>
                    <th data-bitzer-field="cost">Cost</th>
                    <th data-bitzer-field="quantity_available">Quantity Available</th>
                    <th data-bitzer-field="lastModifiedOn">Last Modified</th>
                    
         <?php
            if(is_array($results_list))
            {
                //print_r($results_list); exit();
                foreach($results_list as $sresult)
                {
                    
         ?>
                    <tr data-bitzer-pk-name="list_name"
                        data-bitzer-pk-value="<?php echo $list_name; ?>">

                        <td><?php echo $list_name; ?></td>
                        <td><?php echo $sresult->getField('itemId'); ?></td>
                        <td><?php echo $sresult->getField('salesDescription'); ?></td>
                        <td><?php echo ($sresult->getField('cost') != null && $sresult->getField('cost') > 0) ? $sresult->getField('cost') : "0"; ?></td>
                        <td><?php echo ($sresult->getField('quantityAvailable') != null && $sresult->getField('quantityAvailable') > 0) ? $sresult->getField('quantityAvailable') : "0"; ?></td>
                        <td>2011-04-21 11:28:00 PST</td>
                    </tr>
         <?php
                    
                }
            }
       }
         ?>
       </table>
  </body>
</html>